﻿namespace net.zxteam.ZXLexer
{
    using System;

    public sealed class StringLexerSource : ILexerSource
    {
        private readonly string _text;
        private int _offset = -1;

        public StringLexerSource(string text)
        {
            if (text == null) throw new ArgumentNullException();

            this._text = text;
        }

        public ITransactionUsingScope CreateTransactionScope()
        {
            throw new NotImplementedException();
        }

        public IUsingScope CreateIndentScope()
        {
            throw new NotImplementedException();
        }

        public int Position { get { return this._offset; } }

        public char? Peek()
        {
            if (this._offset >= 0 && this._offset < this._text.Length)
            {
                return this._text[this._offset];
            }

            return null;
        }

        public char? Read()
        {
            if (this._offset < this._text.Length)
            {
                return this._text[this._offset++];
            }

            return null;
        }
    }
}
